package com.kantboot.functional.pay.order.repository;

import com.kantboot.functional.pay.order.domian.entity.FunctionalPayOrder;
import io.lettuce.core.dynamic.annotation.Param;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface FunctionalPayOrderRepository extends JpaRepository<FunctionalPayOrder, Long> {

    @Modifying
    @Transactional
    @Query("""
        update FunctionalPayOrder set statusCode = :statusCode where id = :id
    """)
    void updateStatusCodeById(
            @Param("id") Long id,
            @Param("statusCode") String statusCode);

    /**
     * 根据id修改payMethodCode
     */
    @Modifying
    @Transactional
    @Query("""
        update FunctionalPayOrder set payMethodCode = :payMethodCode where id = :id
    """)
    void updatePayMethodCodeById(
            @Param("id") Long id,
            @Param("payMethodCode") String payMethodCode);

    /**
     * 根据状态编码查询
     */
    List<FunctionalPayOrder> findByStatusCode(String statusCode);

}
